import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

enum Team {
	WHITE, BLACK
}

public class ChessMen extends JComponent {

	public int x, y;
	private Team team;
	public BufferedImage img;
	private String type;
	public boolean selected = false;
	
	public boolean isActive=true;

	ChessMen(String type, Team t, int x, int y) {
		this.team = t;
		this.x = x;
		this.y = y;
		this.type = type;
		this.isActive = true;
		

		if (t == Team.BLACK) {
			if (type.equalsIgnoreCase("rook")) {
				try {
					img = ImageIO.read(new File("images\\bRook.png"));
				} catch (IOException e) {
				}
			}

			else if (type.equalsIgnoreCase("king")) {
				try {
					img = ImageIO.read(new File("images\\bKing.png"));
				} catch (IOException e) {
				}
			}
			
			else 			if(type.equalsIgnoreCase("bishop")){
				try {
					img = ImageIO.read(new File("images\\bBishop.png"));
				} catch (IOException e) {
				}
			}
			
			else 			if(type.equalsIgnoreCase("queen")){
				try {
					img = ImageIO.read(new File("images\\bQueen.png"));
				} catch (IOException e) {
				}
			}
			
			else 			if(type.equalsIgnoreCase("pawn")){
				try {
					img = ImageIO.read(new File("images\\bPawn.png"));
				} catch (IOException e) {
				}
			}
			
			else 			if(type.equalsIgnoreCase("knight")){
				try {
					img = ImageIO.read(new File("images\\bKnight.png"));
				} catch (IOException e) {
				}
			}

		}
		
		else 		 {
			if (type.equalsIgnoreCase("rook")) {
				try {
					img = ImageIO.read(new File("images\\wRook.png"));
				} catch (IOException e) {
				}
			}

			else if (type.equalsIgnoreCase("king")) {
				try {
					img = ImageIO.read(new File("images\\wKing.png"));
				} catch (IOException e) {
				}
			}
			
			else 			if(type.equalsIgnoreCase("bishop")){
				try {
					img = ImageIO.read(new File("images\\wBishop.png"));
				} catch (IOException e) {
				}
			}
			
			else 			if(type.equalsIgnoreCase("queen")){
				try {
					img = ImageIO.read(new File("images\\wQueen.png"));
				} catch (IOException e) {
				}
			}
			
			else 			if(type.equalsIgnoreCase("pawn")){
				try {
					img = ImageIO.read(new File("images\\wPawn.png"));
				} catch (IOException e) {
				}
			}
			
			else 			if(type.equalsIgnoreCase("knight")){
				try {
					img = ImageIO.read(new File("images\\wKnight.png"));
				} catch (IOException e) {
				}
			}

		}

	}

	public void draw(Graphics g) {
		



		if(isActive){
			if(!selected){
				g.drawImage(img, 47 + 75 * (x-1), 47+75*(y-1), this);

			}
			
			else{
				g.drawImage(img, 47 + 75 * (x-1), 47+75*(y-1), this);
				

			}

		}

	}
	
	public String toString(){
		return this.type+ this.team+this.selected;
	}

}
